package com.cloud.exception;

/**
 * 业务异常基类,所有业务异常都必须继承于此异常
 *
 * @author yzj
 */
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    // 异常信息
    private String msg;

    // 具体异常码
    private Integer code;

    public BaseException(Integer code, String msg, Object... args) {
        super(String.format(msg, args));
        this.code = code;
        this.msg = String.format(msg, args);
    }

    public BaseException() {
        super();
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public BaseException(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public Integer getCode() {
        return code;
    }

    /**
     * 实例化异常
     *
     * @param msg
     * @param args
     * @return
     */
    public BaseException newInstance(String msg, Object... args) {
        return new BaseException(this.code, msg, args);
    }
}
